﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace PlayDeezGames.Common
{
    public partial class GridColumn : UserControl
    {
        private List<GridCell> cells = new List<GridCell>();
        public GridCell this[int index]
        {
            get
            {
                if (index >= 0 && index < cells.Count)
                {
                    return cells[index];
                }
                else
                {
                    return null;
                }
            }
        }
        int column;
        public int Column
        {
            get
            {
                return column;
            }
            set
            {
                column = value;
                foreach (var cell in cells)
                {
                    cell.Column = value;
                }
            }
        }

        public int Rows
        {
            get
            {
                return cells.Count;
            }
            set
            {
                if (value != cells.Count)
                {
                    while (value < cells.Count)
                    {
                        LayoutRoot.RowDefinitions.Remove(LayoutRoot.RowDefinitions[0]);
                        LayoutRoot.Children.Remove(cells[cells.Count - 1]);
                        cells.Remove(cells[cells.Count - 1]);
                    }
                    while (value > cells.Count)
                    {
                        LayoutRoot.RowDefinitions.Add(new RowDefinition());
                        GridCell cell = new GridCell();
                        LayoutRoot.Children.Add(cell);
                        cell.Row = cells.Count;
                        cell.Layers = Layers;
                        Grid.SetRow(cell, cells.Count);
                        cells.Add(cell);
                    }
                    Column = Column;
                }
            }
        }

        private int layers = 0;
        public int Layers
        {
            get
            {
                return layers;
            }
            set
            {
                if (layers != value)
                {
                    layers = value;
                    foreach (GridCell cell in cells)
                    {
                        cell.Layers = layers;
                    }
                }
            }
        }
        public GridColumn()
        {
            InitializeComponent();
        }
    }
}
